package com.twu.biblioteca.operation;

import com.twu.biblioteca.exception.InvalidCheckReturnException;
import com.twu.biblioteca.model.Movie;
import com.twu.biblioteca.service.MovieService;
import com.twu.biblioteca.util.CommonUtils;

import static com.twu.biblioteca.util.Messages.THANK_YOU_FOR_RETURNING_THE_MOVIE;
import static java.lang.String.format;

public class ReturnMovieOperation extends Operation {

    private MovieService movieService;

    public void setMovieService(MovieService movieService) {
        this.movieService = movieService;
    }

    @Override
    public String operate(String[] args) throws InvalidCheckReturnException {

        Movie movie = movieService.returnMovie(CommonUtils.getInputId(args[0]), args[1]);
        return format(THANK_YOU_FOR_RETURNING_THE_MOVIE + "|%s|%s|%s",
                movie.getMovieName(),
                movie.getDirector(),
                movie.getRating()
        );
    }
}
